<template>
	<view style="padding: 5px;position: relative; ">
		<view  @click="clicks()" >
			<u-search :placeholder="set.text" :showAction="false" :shape="set.shape" 
			:borderColor="set.border_color"
			:bgColor="set.bcolor"
			:placeholderColor="set.color"
			:searchIconColor="set.color"
			@search="search()"
			v-model="keyword"
			></u-search>
		</view>
	</view>
</template>
<script>
	export default {
		name:"diy-search",
		data() {
			return {
				keyword:"",
				search_type:"",
				curPage:""
			};
		},props:{
			set:{
				default:{
					color:'rgb(144, 147, 153)',
					bcolor:'#fff',
					border_color:"#ccc",
					text:"请输入关键字",
					search_type:"",
					shape:"round",
					jump_search_page:0,//是否跳转到搜索页面
				}
			},
			keys:{
				default:""
			}
		},created() {
			if(this.$pageData.param&&this.$pageData.param.search_type){
				this.search_type = this.moxi.copy(this.$pageData.param.search_type);
			}else{
				this.search_type = this.set.search_type;
			}
			this.curPage = this.moxi.copy(this.$pageData.curPageName)
			this.$pageData.search_type = this.set.search_type;
		},methods:{
			clicks(){
				if(this.set.jump_search_page==1&&this.curPage!='pages/index/search'){
					this.navto('pages/index/search?search_type='+this.search_type)
				}
			},
			search(){
				if(!this.keyword.length){
					return false;
				}
				let data = this.moxiCache('search_tag_list')
				const info = {keyword:this.keyword,search_type:this.search_type};
				if(!data.length){
					data = [info]
				}else{
					data.unshift(info)
				}
				
				this.moxiCache('search_tag_list',data.slice(0,50))
				if(this.search_type=='goods'){
					this.navto('page_mall/goods/list?column_type='+this.search_type+'&search='+this.keyword)
				}else if(this.search_type=='article'){
					this.navto('pages/index/list?column_type='+this.search_type+'&search='+this.keyword)
				}
			}
		}
	}
</script>

<style>

</style>